package com.yunchang.springboot.scheduled.amazon.mws.report.start;

import com.yunchang.springboot.models.Area;
import com.yunchang.springboot.models.Shop;
import com.yunchang.springboot.models.log.BaseMwsReportLogDO;
import com.yunchang.springboot.scheduled.amazon.mws.report.common.BaseMwsReport;
import com.yunchang.springboot.scheduled.amazon.mws.report.detail.GetReportProcessDetail;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.List;
import java.util.Map;


/**
 * 亚马逊mws获取报告数据启动类
 *
 * @author czw
 */
@Slf4j
@Component
public class MwsReportStart extends BaseMwsReport {
    /**
     * 获取报告实现细节方法类
     */
    @Resource
    GetReportProcessDetail getReportProcessDetail;

    /**
     * 获取报告数据开始的方法
     *
     * @param reportName
     * @param reportType
     * @param timeScope       报告获取时间范围
     * @param getReportArea
     * @throws Exception
     */
    public void getReportData(String reportName, String reportType, String timeScope, Integer getReportArea, Integer reportInfoId) throws Exception {
        Map<String, XMLGregorianCalendar> reportTimeScope = getReportProcessDetail.getReportTimeScope(timeScope);
        // 根据任务名获取店铺及区域
        List<Map<Shop, Area>> shopAreaMapList = getShopAndAreaInfoByGetReportArea(getReportArea);
        for (Map<Shop,Area> shopAreaMap:shopAreaMapList) {
            for (Shop shopKey : shopAreaMap.keySet()) {

                BaseMwsReportLogDO mwsReportLog = new BaseMwsReportLogDO();
                // 异步调用获取报告方法
                getReportProcessDetail.reportDetail(reportName,reportInfoId, reportType,timeScope, reportTimeScope, shopKey, shopAreaMap.get(shopKey),mwsReportLog);
            }
        }
    }
}
